﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using CUWo.App.CustomControl;
using CUWo.Common.Entities.WoInterface.HttpJsonResult;

/**
 * 创建时间：2014/11/25 13:32:12
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace CUWo.App.WoControls
{
    public class WoNewsContentTemplateSelector : DataTemplateSelector
    {
        /// <summary>
        /// 有图新闻的样式
        /// </summary>
        public DataTemplate HasImage { get; set; }

        /// <summary>
        /// 无图新闻的样式
        /// </summary>
        public DataTemplate NoImage { get; set; }

        /// <summary>
        /// 根据NewsInf的属性，返回对应的DataTemplate 
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="container"></param>
        /// <returns></returns>
 
        public override DataTemplate SelectTemplate(object obj, DependencyObject container)
        {

            NewsInf item = obj as NewsInf;
            if (item != null)
            {
                if (item.PicInf != null && item.PicInf.Count > 0 && !string.IsNullOrWhiteSpace(item.PicInf[0].Path))
                {
                    return HasImage;
                }
                else
                {
                    return NoImage;
                }
            }
            return base.SelectTemplate(item, container);
        }
    }
}
